package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CImage;
import com.ruoyi.system.service.ICImageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图片对应商品表Controller
 * 
 * @author ruoyi
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/camp/image")
public class CImageController extends BaseController
{
    @Autowired
    private ICImageService cImageService;

    /**
     * 查询图片对应商品表列表
     */
    @PreAuthorize("@ss.hasPermi('camp:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(CImage cImage)
    {
        startPage();
        List<CImage> list = cImageService.selectCImageList(cImage);
        return getDataTable(list);
    }

    /**
     * 导出图片对应商品表列表
     */
    @PreAuthorize("@ss.hasPermi('camp:image:export')")
    @Log(title = "图片对应商品表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CImage cImage)
    {
        List<CImage> list = cImageService.selectCImageList(cImage);
        ExcelUtil<CImage> util = new ExcelUtil<CImage>(CImage.class);
        util.exportExcel(response, list, "图片对应商品表数据");
    }

    /**
     * 获取图片对应商品表详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:image:query')")
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") String imageId)
    {
        return success(cImageService.selectCImageByImageId(imageId));
    }

    /**
     * 新增图片对应商品表
     */
    @PreAuthorize("@ss.hasPermi('camp:image:add')")
    @Log(title = "图片对应商品表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CImage cImage)
    {

        return toAjax(cImageService.insertCImage(cImage));
    }

    /**
     * 修改图片对应商品表
     */
    @PreAuthorize("@ss.hasPermi('camp:image:edit')")
    @Log(title = "图片对应商品表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CImage cImage)
    {
        return toAjax(cImageService.updateCImage(cImage));
    }

    /**
     * 删除图片对应商品表
     */
    @PreAuthorize("@ss.hasPermi('camp:image:remove')")
    @Log(title = "图片对应商品表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable String[] imageIds)
    {
        return toAjax(cImageService.deleteCImageByImageIds(imageIds));
    }
}
